<template>
  <view class="news-card">
    <!-- 新闻内容区域 -->
    <view class="news-content">
      <!-- 标题区域（包含置顶标签） -->
      <view class="news-title">
        <text v-if="news.isTop" class="top-tag">置顶</text>
        <text class="title-text">{{ news.title }}</text>
      </view>
      
      <!-- 来源、评论数和时间 -->
      <view class="news-meta">
        <view class="news-source">
          <text>{{ news.source }}</text>
          <text v-if="news.comments" class="comment-count">{{ news.comments }}评</text>
        </view>
        <text class="news-time">{{ news.time }}</text>
      </view>
      
      <!-- 标签区域 -->
      <view class="news-tags" v-if="news.tags && news.tags.length">
        <text class="tag-item" v-for="(tag, i) in news.tags" :key="i">{{ tag }}</text>
      </view>
    </view>
    
    <!-- 点击反馈效果 -->
    <view class="click-mask" @click="$emit('click', news)"></view>
  </view>
</template>

<script>
export default {
  name: 'news-card',
  // 接收父组件传递的新闻数据
  props: {
    news: {
      type: Object,
      required: true,
      default: () => ({})
    }
  }
}
</script>

<style scoped>
.news-card {
  padding: 20rpx 16rpx;
  border-bottom: 1px solid #f0f0f0;
  position: relative;
  background-color: #fff;
}

.news-content {
  display: flex;
  flex-direction: column;
}

.news-title {
  font-size: 34rpx;
  color: #333;
  line-height: 48rpx;
  margin-bottom: 14rpx;
  display: flex;
  align-items: flex-start;
  word-break: break-word;
}

.top-tag {
  background-color: #e02020;
  color: #fff;
  font-size: 22rpx;
  padding: 2rpx 8rpx;
  border-radius: 4rpx;
  margin-right: 10rpx;
  margin-top: 4rpx;
  line-height: 1.2;
}

.title-text {
  flex: 1;
}

.news-meta {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 26rpx;
  color: #888;
  margin-bottom: 12rpx;
}

.news-source {
  display: flex;
  align-items: center;
  gap: 16rpx;
}

.comment-count {
  color: #666;
}

.news-time {
  white-space: nowrap;
}

.news-tags {
  display: flex;
  gap: 12rpx;
  flex-wrap: wrap;
  margin-top: 8rpx;
}

.tag-item {
  font-size: 24rpx;
  color: #1890ff;
  background-color: #e6f7ff;
  padding: 2rpx 12rpx;
  border-radius: 4rpx;
}

.click-mask {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 1;
}
</style>